import java.sql.*;

public class questJDBC {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //注册驱动(确认使用那个数据库)
        Class.forName("com.mysql.cj.jdbc.Driver");
        //连接数据库
        String url = "jdbc:mysql://localhost:3306/user";
        Connection conn = DriverManager.getConnection(url, "root", "123456");
        //编写SQL语句
        String sql="select id,username,password from user";
        //把SQL语句发送给数据库(数据库执行代码,并返回执行结果)
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        //处理SQL的执行结果
        while (rs.next()) {
            System.out.print(rs.getInt("id")+"\t");
            System.out.print(rs.getString("username")+"\t");
            System.out.println(rs.getString("password"));
        }
        //释放资源(断开和数据库的连接)
        rs.close();
        stmt.close();
        conn.close();
    }
}
